<?php

namespace app\models\db;

use Yii;

/**
 * This is the model class for table "t_discount".
 *
 * @property string $id
 * @property string $content
 * @property integer $goods_score
 * @property integer $express_pack
 * @property integer $express_speed
 * @property integer $express_felling
 * @property string $create_datetime
 * @property string $order_goods_id
 * @property string $user_id
 *
 * @property OrderGoods $orderGoods
 */
class Discount extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 't_discount';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'user_id'], 'required'],
            [['goods_score', 'express_pack', 'express_speed', 'express_felling'], 'integer'],
            [['create_datetime'], 'safe'],
            [['id', 'order_goods_id', 'user_id'], 'string', 'max' => 36],
            [['content'], 'string', 'max' => 200],
            [['order_goods_id'], 'unique'],
            [['order_goods_id'], 'exist', 'skipOnError' => true, 'targetClass' => OrderGoods::className(), 'targetAttribute' => ['order_goods_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'content' => 'Content',
            'goods_score' => 'Goods Score',
            'express_pack' => 'Express Pack',
            'express_speed' => 'Express Speed',
            'express_felling' => 'Express Felling',
            'create_datetime' => 'Create Datetime',
            'order_goods_id' => 'Order Goods ID',
            'user_id' => 'User ID',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getOrderGoods()
    {
        return $this->hasOne(OrderGoods::className(), ['id' => 'order_goods_id']);
    }
}
